package com.sx.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sx.bean.Organization;
import com.sx.dao.OrganizationDao;
import com.sx.service.OrganizationService;
import com.sx.util.Pagination;
import com.sx.util.Utils;

@Service
public class OrganizationServiceImpl implements OrganizationService{

	@Autowired
	private OrganizationDao organizationDao;
	
	@Override
	public Pagination<Organization> getOrg(int pageNumber,int pageSize) {
		List<Organization> orgs = organizationDao.getOrg((pageNumber-1)*pageSize,pageSize);
		int count = organizationDao.getOrgCount();
		Pagination<Organization> page = new Pagination<Organization>();
		page.setPageSize(pageSize);
		page.setPageNumber(pageNumber);
		page.setTotal(count);
		page.setRows(orgs);
		return page;
	}

	@Override
	public int insertOrg(Organization org) {
		org.setOrganUuid(Utils.getUUID());
		organizationDao.insertOrg(org);
		return 1;
	}

	@Override
	public int updateOrg(Organization org) {
		organizationDao.updateOrg(org);
		return 1;
	}

	@Override
	public int deleteOrg(String id) {
		organizationDao.deleteOrg(id);
		return 1;
		
	}

}
